import Vue from 'vue'
import VueRouter from 'vue-router'
import defaultRoutes from './default'
import detailRoutes from './detail'
Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch((err) => err);
};

const routes = [
  ...defaultRoutes,
  ...detailRoutes
]
// 创建路由
const createRouter = function () {
  const router = new VueRouter({
    base: '',
    mode: 'history',
    routes
  })
  return router
}

const router = createRouter()
VueRouter.prototype.createRouter = createRouter;

export default router
